//
//  AllenMyMessageTableView.m
//  自做商城项目
//
//  Created by allenL on 2017/6/21.
//  Copyright © 2017年 tam. All rights reserved.
//

#import "AllenMyMessageTableView.h"
#import "AllenMyMessageTableViewCell.h"

@interface AllenMyMessageTableView()<UITableViewDelegate,UITableViewDataSource>
//message列表需要展示的数据源 --AllenL
@property (strong ,nonatomic) NSArray *messageTableSource;

@end

@implementation AllenMyMessageTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.bounces = NO;
    }
    return self;
}
- (NSArray *)messageTableSource{
    if (!_messageTableSource) {
        _messageTableSource = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AllenMyMessageTablePlist" ofType:@"plist"]];
    }
    return _messageTableSource;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AllenMyMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[AllenMyMessageTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
    }
    //    cell.textLabel.text = [NSString stringWithFormat:@"%li" , indexPath.row];
    cell.sourceDic = self.messageTableSource[indexPath.row];
    
    if (indexPath.row == 3) {
        UIImageView *nextImage = [cell valueForKey:@"nextImage"];
        
        nextImage.hidden = YES;
        UILabel *phoneNum = [[UILabel alloc]init];
        phoneNum.textColor = RGB(123, 124, 128);
        phoneNum.text = @"400-100-1111";
        [cell addSubview:phoneNum];
        
        __weak typeof  (cell) weakSelf = cell;
        [phoneNum mas_makeConstraints:^(MASConstraintMaker *make){
            make.right.equalTo(weakSelf.mas_right).offset(-15);
            make.centerY.equalTo(weakSelf.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(110, 15));
            
        }];
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AllenLog(@"我选中的是第%li",indexPath.row);
}

@end
